﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frogism.Core;
using Frogism.Domain;
using NUnit.Framework;

namespace Frogism.Tests
{
    [TestFixture]
    public class MortgageTests
    {
        Account testAccount;
        Account testRetirmentAccount;
        [SetUp]
        public void Setup()
        {
             testAccount = new Account();
             testAccount.Id = -1;
            
            testAccount.AccountType = DBConst.AccountTypeMortgage;
            testAccount.NextGoalValue = 245000;
            var trans = new Transaction();

            trans.TransactionType = TransactionType.Deposit;
            trans.Amount = (12250);
            trans.AccountId = -1;
            trans.IsConfirmed = true;
            trans.TransactionDate = new DateTime(2009, 9, 14, 0, 0, 0);
            testAccount.SetTransactions(new List<ITransaction>());
            testAccount.Transactions.Add(trans);




            testRetirmentAccount = new Account();
            testRetirmentAccount.Id = -2;

            testRetirmentAccount.AccountType = DBConst.AccountTypeRetirement;
            testRetirmentAccount.NextGoalValue = 2000;
            
            trans = new Transaction();

            trans.TransactionType = TransactionType.Deposit;
            trans.Amount = (2000);
            trans.AccountId = -2;
            trans.IsConfirmed = true;
            trans.TransactionDate = new DateTime(2009, 9, 14, 0, 0, 0);
            testRetirmentAccount.SetTransactions(new List<ITransaction>());
            testRetirmentAccount.Transactions.Add(trans);
        }
        [Test]
        public void MortgateType()
        {
            Assert.AreEqual(DBConst.AccountTypeMortgage, testAccount.AccountType);
        }
        [Test]
        public void StartingValue()
        {
            Assert.AreEqual(0, testAccount.Start);
        }
        [Test]
        public void Balance()
        {
            Assert.AreEqual(12250, testAccount.Balance);
        }
        [Test]
        public void NextGoal()
        {
            Assert.AreEqual(245000, testAccount.NextGoalValue);
        }

        [Test]
        public void ToGo()
        {
            Assert.AreEqual(245000 - 12250, testAccount.ToGo);
        }
        [Test]
        public void NetWorth()
        {
            var mm = new MoneyManager();
            var accounts = new List<IAccount>();
            accounts.Add(testAccount);
            var nw = mm.GetNetWorth(accounts);
            Assert.AreEqual(7, nw.Count());
            var nwM = nw.FirstOrDefault(f => f.Label == "Mortgage");
            Assert.IsNotNull(nwM);
            Assert.AreEqual(12250, nwM.Balance, "Balance");
            Assert.AreEqual(12250, nwM.Progress, "Progress");
            Assert.AreEqual(245000 - 12250, nwM.ToGo, "ToGo");

            var networth = nw.FirstOrDefault(f => f.Label == "NetWorth");
            Assert.IsNotNull(networth);
            Assert.AreEqual(12250, networth.Balance, "Balance");
            Assert.AreEqual(12250, networth.Progress, "Progress");
            Assert.AreEqual(245000 - 12250, networth.ToGo, "ToGo");
        }
        [Test]
        public void When65()
        {
            var mm = new MoneyManager();
            var accounts = new List<IAccount>();
            accounts.Add(testRetirmentAccount);
            var nw = mm.GetNetWorth(accounts);
            var nwM = nw.FirstOrDefault(f => f.Label == "Retirement");
            Assert.IsNotNull(nwM);
            Assert.Less(33,nwM.YearsTillRetirement);
            Assert.Greater(34, nwM.YearsTillRetirement);


        }
    }
}